package com.yz.jdd.module.main.adapter;


import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import com.yz.jdd.R;
import com.yz.jdd.module.main.entity.MenuInfoBean;

import java.util.List;

/**
 * 首页菜单
 * 2019.7.16 , ljm
 */

public class MoudleMenuAdapter extends BaseAdapter {

    private Context context;
    private List<MenuInfoBean.ConfigBean>  beanList;

    public MoudleMenuAdapter(Context context, List<MenuInfoBean.ConfigBean> beanList) {
        this.context = context;
        this.beanList = beanList;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public Object getItem(int i) {
        return beanList.get(i);
    }

    @Override
    public int getCount() {
        return beanList.size();
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_module_menu, viewGroup, false);
            viewHolder = new ViewHolder();
            viewHolder.title = (TextView) view.findViewById(R.id.tv_title);
            viewHolder.des = (TextView) view.findViewById(R.id.tv_des);
            viewHolder.img = (ImageView) view.findViewById(R.id.img);
            viewHolder.line = (View) view.findViewById(R.id.line);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }

        MenuInfoBean.ConfigBean configBean=beanList.get(i);
        if(configBean!=null){
            if (!TextUtils.isEmpty(configBean.title) ){
                viewHolder.title.setText(configBean.title);
            }

            if (!TextUtils.isEmpty(configBean.desc)) {
                viewHolder.des.setText(configBean.desc);
            }

            if(!TextUtils.isEmpty(configBean.iosIcon)){
                Glide.with(context).load(configBean.iosIcon).into(viewHolder.img);
            }
        }

//        if (!StringUtils.isNullOrEmpty(beanList.get(i).getAndroidIcon())) {
////            Log.i("ljm", beanList.size() + " / ---------/ " + i);
////            Log.i("ljm", beanList.get(i).title + " / " + beanList.get(i).getAndroidIcon());
//            int resID = context.getResources().getIdentifier(beanList.get(i).getAndroidIcon(), "mipmap", "com.yz.jdd");
//            viewHolder.img.setBackgroundResource(resID);
//        }


//        switch ("123"){
//            case "对账单":
//                viewHolder.des.setText("核对结算资金");
//                viewHolder.img.setBackgroundResource(R.mipmap.dzd);
//                break;
//            case "经营分析":
//                viewHolder.des.setText("商家数据分析");
//                viewHolder.img.setBackgroundResource(R.mipmap.jyfx);
//                break;
//            case "小程序":
//                viewHolder.des.setText("线上开店神器");
//                viewHolder.img.setBackgroundResource(R.mipmap.smail_program);
//                break;
//            case "会员管理":
//                viewHolder.des.setText("会员精细化管理");
//                viewHolder.img.setBackgroundResource(R.mipmap.vip_manage);
//                break;
//            case "返现营销":
//                viewHolder.des.setText("创新方案助力经营");
//                viewHolder.img.setBackgroundResource(R.mipmap.cashback_marketing);
//                break;
//            case "短信推广":
//                viewHolder.des.setText("实现客户精准触达");
//                viewHolder.img.setBackgroundResource(R.mipmap.sms_marketing);
//                break;
//        }

        return view;
    }

    class ViewHolder {
        TextView title;
        TextView des;
        ImageView img;
        View line;
    }
}
